import { Modal } from "ant-design-vue";
import type { ModalFuncProps } from "ant-design-vue";
import { useI18n } from "/@/locales/useI18n";
function getOptions(options?: ModalFuncProps) {
  const { t } = useI18n();
  options = Object.assign<ModalFuncProps, ModalFuncProps>(
    {
      title: t("common.tip"),
      okText: t("common.ok"),
      cancelText: t("common.cancel"),
      centered: true,
      closable: true,
      class: "sl-info-modal",
      zIndex: 2000,
    },
    options || {}
  );
  return options;
}
interface ModalFunResult {
  update: (options: ModalFuncProps) => void;
  destroy: () => void;
}
interface ModalFuncObj {
  info: (options: ModalFuncProps) => ModalFunResult;
  success: (options: ModalFuncProps) => ModalFunResult;
  error: (options: ModalFuncProps) => ModalFunResult;
  warning: (options: ModalFuncProps) => ModalFunResult;
  confirm: (options: ModalFuncProps) => ModalFunResult;
  warningConfirm: (options: ModalFuncProps) => ModalFunResult;
}
const InfoModal: ModalFuncObj = {
  info(options?) {
    return Modal.info(getOptions(options));
  },
  success(options?) {
    return Modal.success(getOptions(options));
  },
  error(options?) {
    return Modal.error(getOptions(options));
  },
  warning(options?) {
    return Modal.warning(getOptions(options));
  },
  confirm(options?) {
    return Modal.confirm(getOptions(options));
  },
  warningConfirm(options?) {
    options = getOptions(options);
    options.okButtonProps = {
      type: "primary",
      danger: true,
    };
    return Modal.confirm(options);
  },
};
export default InfoModal;
